{% extends "../../base.html" %}
{% block content %}

  <script language="javascript" type="text/javascript">

    function getPersLink(_p)
    {
      var html = '<a href="/trip/person?pid=' + _p +'">' + _p + '</a>';
      document.write(html);
      return true;
    }

    function getPersMark(_me, _t)
    {
      var html = '';
      if (_me == 1)
        if (_t == 1)
          html = '<div class="marked">';
        else
          html = '</div>';
      document.write(html);
      return true;
    }

    function myClick(_num)
    {
      var frm = document.getElementById("fld_form");
      var act = frm.elements["action"];
      switch (_num)
      {
        case 1: act.value = "insert"; break;
        case 2: act.value = "update"; break;
        case 3: act.value = "delete"; break;
        case 4: act.value = "cancel"; break;
        case 5: act.value = "back";   break;
        default: act.value = "undef"; 
      }
      frm.elements["me"].value = frm.elements["me"].checked.toString();
      frm.Submit();
      return true;
    }

  </script>

  <div id="gmenu" class="menu"> <a href="/">{{ app_text }}</a> | <a href="/trip">{{ trip_text }}</a> </div>
  <div class="PageTitle">  {{page_title}}  </div>
  <div class="PageStatus"> {{page_status}} </div>

  <form id="fld_form" action="/trip/person" method="post">
    <input name="pid"    type="hidden" value="{{cur.pid}}">
    <input name="action" type="hidden" value="none">
    <table class="fl1">
      <tbody>
      {% if edit_rec %} 
      <tr><td class="fl1"> ID:              </td><td class="fl2"> {{ cur.pid }} </td> </tr>
      {% endif %}
      <tr><td class="fl1"> Имя:             </td><td class="fl2"> <input name="name"   size="15" type="text" value="{{ cur.name }}"   /> </td> </tr>
      <tr><td class="fl1"> Дательный падеж: </td><td class="fl2"> <input name="dative" size="15" type="text" value="{{ cur.dative }}" /> </td> </tr>
      {% if cur.me %} 
      <tr><td class="fl1"> Я:               </td><td class="fl2"> <input name="me" type="checkbox" checked /> </td> </tr>
      {% endif %}
    </tbody></table>
    {% if edit_rec %} 
      <input type="submit" class="LiteButton" id="update" value="Сохранить" onClick="myClick(2)" >
      <input type="submit" class="LiteButton" id="delete" value="Удалить"   onClick="myClick(3)" >
      <input type="submit" class="LiteButton" id="common" value="Отменить"  onClick="myClick(4)" >
    {% else %}
      <input type="submit" class="LiteButton" id="update" value="Добавить"  onClick="myClick(1)" >
    {% endif %}
  </form>

  {% if pers.count %}
  <table class="work">
    <tbody><tr>
      <th class="work"> ID   </th>
      <th class="work"> Имя  </th>
      <th class="work"> Кому </th>
    </tr>
    {% for p in pers %}
    <tr>
      <td class="pid">  <script language="javascript" type="text/javascript">getPersLink({{ p.pid }})</script> </td>
      <td class="work"> <script language="javascript" type="text/javascript">getPersMark({{ p.me }}, 1)</script>
                        {{ p.name   }}
                        <script language="javascript" type="text/javascript">getPersMark({{ p.me }}, 2)</script></td>
      <td class="work"> <script language="javascript" type="text/javascript">getPersMark({{ p.me }}, 1)</script>
                        {{ p.dative }}
                        <script language="javascript" type="text/javascript">getPersMark({{ p.me }}, 2)</script></td>
    </tr>
    {% endfor %}
  </tbody></table>
  {% endif %}

  <br/>Всего персон: {{ pers.count }}<br/>

{% endblock %}
